home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / c-lang / vbcc.lha / vbcc / vbc.h < prev    next >
C/C++ Source or Header  |  1996-05-15  |  13KB  |  497 lines

  1. /*  $VER: vbcc (vbc.h) V0.3     */
  2.  
  3. #include <stdlib.h>
  4. #include <limits.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stddef.h>
  8. #include <stdarg.h>
  9. #include <ctype.h>
  10.  
  11. #include "machine.h"
  12.  
  13. #define eval_constn(a) eval_const(&a->val,a->ntyp->flags)
  14.  
  15. struct function_info{
  16.     struct IC *first_ic,*last_ic;
  17.     struct Var *vars;
  18. };
  19.  
  20. struct Typ{
  21.     int flags;
  22.     struct Typ *next;
  23.     struct struct_declaration *exact;
  24.     int size;
  25. };
  26. #define TYPS sizeof(struct Typ)
  27.  
  28. #define CHAR 1
  29. #define SHORT 2
  30. #define INT 3
  31. #define LONG 4
  32. #define FLOAT 5
  33. #define DOUBLE 6
  34. #define VOID 7
  35. #define POINTER 8
  36. #define ARRAY 9
  37. #define STRUCT 10
  38. #define UNION 11
  39. #define ENUM 12
  40. #define FUNKT 13
  41. #define UNSIGNED 16
  42. #define CONST 64
  43. #define VOLATILE 128
  44. #define UNCOMPLETE 256
  45. #define STRINGCONST 512
  46.  
  47. struct identifier_list{
  48.     char *identifier;
  49.     int length;
  50.     struct identifier_list *next;
  51. };
  52. struct Var{
  53.     int storage_class,priority,flags;
  54.     char *identifier;
  55.     int nesting,offset,index;
  56.     struct Typ *vtyp;
  57.     struct const_list *clist;
  58.     struct Var *next;
  59.     struct function_info *fi;
  60.     struct Var *inline_copy;
  61. };
  62. #define USEDASSOURCE 1
  63. #define USEDASDEST 2
  64. #define DEFINED 4
  65. #define USEDASADR 8
  66. #define GENERATED 16
  67. #define CONVPARAMETER 32
  68. #define TENTATIVE 64
  69. #define USEDBEFORE 128
  70. #define INLINEV 256
  71.  
  72. struct struct_list{
  73.     char *identifier;
  74.     struct Typ *styp;
  75.     int storage_class;
  76. };
  77. struct struct_declaration{
  78.     int count,flags;
  79.     struct struct_declaration *next;
  80.     struct struct_list sl[1];
  81. };
  82. struct struct_identifier{
  83. /*    int flags;*/
  84.     char *identifier;
  85.     struct struct_declaration *sd;
  86.     struct struct_identifier *next;
  87. };
  88.  
  89. struct obj{
  90.     int flags,reg;
  91.     struct Var *v;
  92.     struct AddressingMode *am;
  93.     union atyps{
  94.         zchar vchar;
  95.         zuchar vuchar;
  96.         zshort vshort;
  97.         zushort vushort;
  98.         zint vint;
  99.         zuint vuint;
  100.         zlong vlong;
  101.         zulong vulong;
  102.         zfloat vfloat;
  103.         zdouble vdouble;
  104.         zpointer vpointer;
  105.     }val;
  106. };
  107.  
  108. struct node{
  109.     int flags,lvalue,sidefx;
  110.     struct Typ *ntyp;
  111.     struct node *left;
  112.     struct node *right;
  113.     struct argument_list *alist;
  114.     char *identifier;
  115.     union atyps val;
  116.     struct obj o;
  117. /*  es muss noch sowas wie struct internal_object * dazu    */
  118. };
  119.  
  120. typedef struct node *np;
  121.  
  122. #define NODES sizeof(struct node)
  123.  
  124. #define KOMMA 1
  125. #define ASSIGN 2
  126. #define ASSIGNADD 3
  127. #define ASSIGNSUB 4
  128. #define ASSIGNMULT 5
  129. #define ASSIGNDIV 6
  130. #define ASSIGNMOD 7
  131. #define ASSIGNAND 8
  132. #define ASSIGNXOR 9
  133. #define ASSIGNOR 10
  134. #define ASSIGNLSHIFT 11
  135. #define ASSIGNRSHIFT 12
  136. #define COND 13
  137. #define LOR 14
  138. #define LAND 15
  139. #define OR 16
  140. #define XOR 17
  141. #define AND 18
  142. #define EQUAL 19
  143. #define INEQUAL 20
  144. #define LESS 21
  145. #define LESSEQ 22
  146. #define GREATER 23
  147. #define GREATEREQ 24
  148. #define LSHIFT 25
  149. #define RSHIFT 26
  150. #define ADD 27
  151. #define SUB 28
  152. #define MULT 29
  153. #define DIV 30
  154. #define MOD 31
  155. #define NEGATION 32
  156. #define KOMPLEMENT 33
  157. #define PREINC 34
  158. #define POSTINC 35
  159. #define PREDEC 36
  160. #define POSTDEC 37
  161. #define MINUS 38
  162. #define CONTENT 39
  163. #define ADDRESS 40
  164. #define CAST 41
  165. #define CALL 42
  166. #define INDEX 43
  167. #define DPSTRUCT 44
  168. #define DSTRUCT 45
  169. #define IDENTIFIER 46
  170. #define CEXPR 47
  171. #define STRING 48
  172. #define MEMBER 49
  173. #define CONVCHAR 50
  174. #define CONVSHORT 51
  175. #define CONVINT 52
  176. #define CONVLONG 53
  177. #define CONVFLOAT 54
  178. #define CONVDOUBLE 55
  179. #define CONVVOID 56
  180. #define CONVPOINTER 57
  181. #define CONVUCHAR 58
  182. #define CONVUSHORT 59
  183. #define CONVUINT 60
  184. #define CONVULONG 61
  185. #define ADDRESSA 62
  186. #define FIRSTELEMENT 63
  187. #define PMULT 64
  188. #define ALLOCREG 65
  189. #define FREEREG 66
  190. #define PCEXPR 67
  191. #define TEST 68
  192. #define LABEL 69
  193. #define BEQ 70
  194. #define BNE 71
  195. #define BLT 72
  196. #define BGE 73
  197. #define BLE 74
  198. #define BGT 75
  199. #define BRA 76
  200. #define COMPARE 77
  201. #define PUSH 78
  202. #define POP 79
  203. #define ADDRESSS 80
  204. #define ADDI2P 81
  205. #define SUBIFP 82
  206. #define SUBPFP 83
  207. #define PUSHREG 84
  208. #define POPREG 85
  209. #define POPARGS 86
  210. #define SAVEREGS 87
  211. #define RESTOREREGS 88
  212. #define ILABEL 89
  213. #define DC 90
  214. #define ALIGN 91
  215. #define COLON 92
  216. #define GETRETURN 93
  217. #define SETRETURN 94
  218. #define MOVEFROMREG 95
  219. #define MOVETOREG 96
  220.  
  221. struct argument_list{
  222.     np  arg;
  223.     struct argument_list *next;
  224. };
  225.  
  226. #define AUTO 1
  227. #define REGISTER 2
  228. #define STATIC 3
  229. #define EXTERN  4
  230. #define TYPEDEF 5
  231.  
  232. #define MAXSTRUCTSIZE 20000 /* maximale Groesse fuer struct_declarations in Bytes */
  233. #define MAXI 100 /* maximale Laenge von Identifiers in Bytes    */
  234. #define MAXINPUT 2000    /* maximale Laenge einer Eingabezeile in Bytes  */
  235. #define MAXN 30 /* maximale Verschachtelung von Bloecken */
  236. #define MAXM 100 /* maximale Anzahl an Bloecken pro Funktion (grob) */
  237.  
  238. #define arith(c) ((c)>=CHAR&&(c)<=DOUBLE)
  239.  
  240. extern char *typname[];
  241. extern int sizetab[];
  242. extern char *storage_class_name[];
  243. extern char *ename[];
  244.  
  245. /* Tabelle fuer alignment requirements, maschinenabhaengig */
  246. extern int align[],maxalign;
  247.  
  248. extern void error(int,...);
  249.  
  250. #define ierror(a) error(158,(a),__LINE__,__FILE__)
  251.  
  252. extern void free_fi(struct function_info *);
  253. extern struct Typ *arith_typ(struct Typ*,struct Typ *);
  254. extern void insert_const(np);
  255. extern void insert_const2(union atyps *,int);
  256. extern int int_erw(int);
  257. extern int type_expression(np),compare_pointers(struct Typ *,struct Typ *,int),
  258.     compare_sd(struct struct_declaration *,struct struct_declaration *);
  259. extern np identifier_expression(void),constant_expression(void),string_expression(void),
  260.    postfix_expression(void),unary_expression(void),cast_expression(void),
  261.    multiplicative_expression(void),additive_expression(void),
  262.    shift_expression(void),relational_expression(void),equality_expression(void),
  263.    and_expression(void),exclusive_or_expression(void),
  264.    inclusive_or_expression(void),logical_and_expression(void),
  265.    logical_or_expression(void),conditional_expression(void),
  266.    assignment_expression(void),expression(void),primary_expression(void);
  267. /* puh  */
  268. extern void pre(FILE *,np),pra(FILE *,struct argument_list *);
  269. extern void free_expression(np),free_alist(struct argument_list *);
  270. extern void prd(FILE *,struct Typ *),freetyp(struct Typ *),cpbez(char *m),cpnum(char *m),killsp(void);
  271. extern struct struct_declaration *add_sd(struct struct_declaration *);
  272. extern void free_sd(struct struct_declaration *);
  273. extern void prl(FILE *,struct struct_declaration *);
  274. extern char *add_identifier(char *,int);
  275. extern struct Typ *declarator(struct Typ *),*direct_declarator(struct Typ *),
  276.            *pointer(struct Typ *),*declaration_specifiers(void),
  277.            *clone_typ(struct Typ *);
  278. extern int declaration(int),type_uncomplete(struct Typ *);
  279. extern struct struct_declaration *find_struct(char *);
  280. extern void add_struct_identifier(char *,struct struct_declaration *);
  281. extern void free_si(struct struct_identifier *);
  282. extern char *s,*ident;
  283. extern char string[MAXINPUT],number[MAXI],buff[MAXI];
  284. extern struct struct_declaration *first_sd[MAXN],*last_sd[MAXN],*merk_sdf,*merk_sdl;
  285. extern struct struct_identifier *first_si[MAXN],*last_si[MAXN],*merk_sif,*merk_sil;
  286. extern struct identifier_list *first_ilist[MAXN],*last_ilist[MAXN],*merk_ilistf,*merk_ilistl;
  287. extern void free_ilist(struct identifier_list *);
  288. extern int nesting;
  289. extern char *empty;
  290. extern struct Var *first_var[MAXN],*last_var[MAXN],*merk_varf,*merk_varl;
  291. extern struct Var *add_var(char *,struct Typ *,int,struct const_list *);
  292. extern void free_var(struct Var *);
  293. extern void var_declaration(void);
  294. extern int storage_class_specifiers(void);
  295. extern void enter_block(void),leave_block(void);
  296. extern struct Var *find_var(char *,int);
  297. extern int szof(struct Typ *);
  298.  
  299. extern void eval_const(union atyps *,int);
  300. extern zchar vchar; extern zuchar vuchar;
  301. extern zshort vshort; extern zushort vushort;
  302. extern zint vint; extern zuint vuint;
  303. extern zlong vlong; extern zulong vulong;
  304. extern zfloat vfloat; extern zdouble vdouble;
  305. extern zpointer vpointer;
  306. extern zchar vchar2; extern zuchar vuchar2;
  307. extern zshort vshort2; extern zushort vushort2;
  308. extern zint vint2; extern zuint vuint2;
  309. extern zlong vlong2; extern zulong vulong2;
  310. extern zfloat vfloat2; extern zdouble vdouble2;
  311. extern zpointer vpointer2;
  312.  
  313. extern int usz;
  314.  
  315. extern int DEBUG,MDEBUG;
  316.  
  317. struct IC{
  318.     struct IC *prev,*next;
  319.     int code,typf,defindex,expindex,copyindex;
  320.     struct obj q1,q2,z;
  321. };
  322.  
  323. #define ICS sizeof(struct IC)
  324. #define KONST 1     /*  KONST muss immer am kleinsten sein, um beim swappen */
  325.                     /*  fuer available_expressions und Konstanten nach      */
  326.                     /*  rechts nicht in eine Endlosschleife zu kommen       */
  327. #define VAR 2
  328. #define SCRATCH 8
  329. #define STACK 16
  330. #define DREFOBJ 32
  331. #define REG 64
  332. #define VARADR 128
  333. #define DONTREGISTERIZE 256
  334.  
  335. extern struct IC *first_ic,*last_ic;
  336. extern int regs[MAXR+1],regsa[MAXR+1],regused[MAXR+1],regscratch[MAXR+1],regsize[MAXR+1];
  337. extern struct Var *regsv[MAXR+1],*regsbuf[MAXR+1];
  338. extern int regbnesting[MAXR+1];
  339.  
  340. extern void add_IC(struct IC *),free_IC(struct IC *),insert_IC(struct IC *,struct IC *);
  341. extern void gen_IC(np,int,int),convert(np,int),gen_label(int),savescratch(int,struct IC *,int);
  342. extern int push_args(struct argument_list *,struct struct_declaration *,int);
  343. extern int regok(int,int,int),allocreg(int,int),freturn(struct Typ *);
  344. extern int icok(struct IC *);
  345. extern void free_reg(int);
  346. extern void pric(FILE *,struct IC *),pric2(FILE *,struct IC *);
  347. extern char *regnames[];
  348. extern void probj(FILE *,struct obj *,int,int);
  349.  
  350. extern void printzl(FILE *,zlong),printzul(FILE *,zulong),printzd(FILE *,zdouble);
  351. extern void printval(FILE *,union atyps *,int,int);
  352.  
  353. extern int label;
  354.  
  355. extern FILE *out,*ic1,*ic2,*ppout;
  356.  
  357. extern void statement(void),labeled_statement(void),if_statement(void);
  358. extern void switch_statement(void),while_statement(void),for_statement(void);
  359. extern void do_statement(void),goto_statement(void),continue_statement(void);
  360. extern void break_statement(void),return_statement(void);
  361. extern void expression_statement(void),compound_statement(void),raus(void);
  362. extern void translation_unit(void);
  363. extern int main(int, char *[]);
  364. extern int nocode,registerpri,looppri,currentpri;
  365.  
  366. extern void *mymalloc(size_t);
  367.  
  368. extern np makepointer(np);
  369.  
  370. extern int must_convert(np,int);
  371.  
  372. extern int switch_typ,switch_count,switch_act;
  373. struct llist{
  374.     char *identifier;
  375.     int label,flags,switch_count;
  376.     struct llist *next;
  377.     union atyps val;
  378. };
  379. #define LABELDEFINED 1
  380. #define LABELUSED 2
  381. #define LABELDEFAULT 4
  382. #define LSIZE sizeof(struct llist)
  383. extern struct llist *first_llist,*last_llist;
  384. extern struct llist *find_label(char *),*add_label(char *);
  385. extern void free_llist(struct llist *);
  386.  
  387. extern int endok,return_label,return_value,break_label;
  388. extern struct Var *return_var;
  389. extern struct Typ *return_typ;
  390. extern int local_offset[MAXN];
  391.  
  392. extern void scratch_var(struct obj *,int),get_scratch(struct obj *,int,int);
  393. extern struct obj gen_cond(int,int,int);
  394.  
  395. extern void simple_regs(void);
  396.  
  397. union ppi {char *p;long l;void (*f)(char *);};
  398.  
  399. #define USEDFLAG 1
  400. #define STRINGFLAG 2
  401. #define VALFLAG 4
  402. #define FUNCFLAG 8
  403.  
  404. #define MAXCF 30
  405. extern int c_flags[MAXCF];
  406. extern char *c_flags_name[MAXCF];
  407. extern union ppi c_flags_val[MAXCF];
  408.  
  409. extern int g_flags[MAXGF];
  410. extern char *g_flags_name[MAXGF];
  411. extern union ppi g_flags_val[MAXGF];
  412.  
  413.  
  414. extern FILE *open_out(char *,char *);
  415.  
  416. extern char *inname;
  417.  
  418. extern void gen_code(FILE *,struct IC *,struct Var *,int);
  419.  
  420. extern int init_cg(void);
  421.  
  422. extern void gen_vars(struct Var *);
  423.  
  424. extern int max_offset;
  425.  
  426. extern int function_calls;
  427.  
  428. struct const_list{
  429.     union atyps val;
  430.     np tree;
  431.     struct const_list *other,*next;
  432. };
  433. extern struct const_list *first_clist,*last_clist;
  434. #define CLS sizeof(struct const_list)
  435.  
  436. /*  Format der Tabelle fuer Fehlermeldungen */
  437. struct err_out{
  438.     char *text;
  439.     int  flags;
  440. };
  441. /*  Flags fuer err_out.flags    */
  442. #define ERROR       1
  443. #define WARNING     2
  444. #define ANSIV       4
  445. #define INTERNAL    8
  446. #define FATAL      16
  447. #define MESSAGE    32
  448. #define DONTWARN   64
  449. #define PREPROC   128
  450.  
  451. extern struct err_out err_out[];
  452. extern int err_num;
  453.  
  454. extern void gen_dc(FILE *,int,struct const_list *);
  455. extern void gen_ds(FILE *,int,struct Typ *),gen_var_head(FILE *,struct Var *);
  456. extern void gen_align(FILE *,int);
  457. extern void free_clist(struct const_list *);
  458.  
  459. extern void remove_IC(struct IC *);
  460.  
  461. extern zlong t_min[];
  462. extern zulong t_max[];
  463.  
  464. extern int afterlabel;
  465.  
  466. extern int goto_used;
  467.  
  468. extern int errors;
  469. extern int ic_count;
  470.  
  471.  
  472. /*  fuer den Praeprozessor  */
  473.  
  474. #define MAXPPINPUT 2000     /*  maximale Laenge einer Eingabezeile  */
  475. #define MAXINCNESTING 50    /*  maximale Verschachtelung von Includes   */
  476.  
  477. extern FILE *in[MAXINCNESTING];    /*  Sourcefiles     */
  478. extern int zn[MAXINCNESTING];      /*  Zeilennummern   */
  479. extern char *filename[MAXINCNESTING];   /*  Filenamen   */
  480. extern int incnesting;             /*  aktuelle Verschachtelungstiefe  */
  481. extern unsigned long linenr;                 /*  Zeilennummer */
  482.  
  483. #define MAXINCPATHS 20      /*  maximale Anzahl der Includepfade    */
  484.  
  485. extern char *incpath[MAXINCPATHS];   /*  Includepfade    */
  486.                                             /*  Rest ist NULL   */
  487.  
  488. extern int incpathc;     /*  Anzahl der Includepfade     */
  489.  
  490. int pp_init(void);
  491. void pp_free(void);
  492. int pp_include(char *filename);
  493. int pp_nextline(void);
  494. int pp_define(char *text);
  495.  
  496. int only_inline;
  497.